home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / text / edit / vim60rt.lha / Vim / vim60 / doc / if_perl.txt < prev    next >
Encoding:
Text File  |  2001-09-26  |  8.3 KB  |  233 lines

  1. *if_perl.txt*   For Vim version 6.0.  Last change: 2001 Sep 03
  2.  
  3.  
  4.           VIM REFERENCE MANUAL    by Sven Verdoolaege
  5.                      and Matt Gerassimof
  6.  
  7. Perl and Vim                *perl* *Perl*
  8.  
  9. 1. Editing Perl files            |perl-editing|
  10. 2. Compiling VIM with Perl interface    |perl-compiling|
  11. 3. Using the Perl interface        |perl-using|
  12.  
  13. {Vi does not have any of these commands}
  14.  
  15. The Perl interface only works when Vim was compiled with the |+perl| feature.
  16.  
  17. ==============================================================================
  18. 1. Editing Perl files                    *perl-editing*
  19.  
  20. Vim syntax highlighting supports Perl and POD files.  Vim assumes a file is
  21. Perl code if the filename has a .pl or .pm suffix. Vim also examines the first
  22. line of a file, regardless of the filename suffix, to check if a file is a
  23. Perl script (see scripts.vim in Vim's syntax directory).  Vim assumes a file
  24. is POD text if the filename has a .POD suffix.
  25.  
  26. To use tags with Perl, you need a recent version of Exuberant ctags.  Look
  27. here:
  28.     http://ctags.sourceforge.net
  29.  
  30. Alternatively, you can use the Perl script pltags.pl, which is shipped with
  31. Vim in the $VIMRUNTIME/tools directory.  This script has currently more
  32. features than Exuberant ctags' Perl support.
  33.  
  34. ==============================================================================
  35. 2. Compiling VIM with Perl interface            *perl-compiling*
  36.  
  37. To compile Vim with Perl interface, you need Perl 5.004 (or later).  Perl must
  38. be installed before you compile Vim.  Vim's Perl interface does NOT work with
  39. the 5.003 version that has been officially released!  It will probably work
  40. with Perl 5.003_05 and later.
  41.  
  42. The Perl patches for Vim were made by:
  43.     Sven Verdoolaege <skimo@breughel.ufsia.ac.be>
  44.     Matt Gerassimof
  45.  
  46. Perl for MS-Windows can be found at:
  47. http://www.perl.com/CPAN-local/ports/nt/Standard/x86/
  48.  
  49. ==============================================================================
  50. 3. Using the Perl interface                *perl-using*
  51.  
  52.                             *:perl* *:pe*
  53. :pe[rl] {cmd}        Execute Perl command {cmd}. The current package
  54.             is "main".
  55.  
  56. :pe[rl] << {endpattern}
  57. {script}
  58. {endpattern}
  59.             Execute Perl script {script}.
  60.             {endpattern} must NOT be preceded by any white space.
  61.             If {endpattern} is omitted, it defaults to a dot '.'
  62.             like for the |:append| and |:insert| commands.  This
  63.             form of the |:perl| command is mainly useful for
  64.             including perl code in vim scripts.
  65.  
  66. Example vim script: >
  67.  
  68.     function! WhitePearl()
  69.     perl << EOF
  70.         VIM::Msg("pearls are nice for necklaces");
  71.         VIM::Msg("rubys for rings");
  72.         VIM::Msg("pythons for bags");
  73.         VIM::Msg("tcls????");
  74.     EOF
  75.     endfunction
  76. <
  77.  
  78.                             *:perldo* *:perld*
  79. :[range]perld[o] {cmd}    Execute Perl command {cmd} for each line in the
  80.             [range], with $_ being set to the text of each line in
  81.             turn, without a trailing <EOL>. Setting $_ will change
  82.             the text, but note that it is not possible to add or
  83.             delete lines using this command.
  84.             The default for [range] is the whole file: "1,$".
  85.  
  86. Here are some things you can try: >
  87.  
  88.   :perl $a=1
  89.   :perldo $_ = reverse($_);1
  90.   :perl VIM::Msg("hello")
  91.   :perl $line = $curbuf->Get(42)
  92. <
  93.                             *E299*
  94. Executing Perl commands in the |sandbox| is limited.  ":perldo" will not be
  95. possible at all.  ":perl" will be evaluated in the Safe environment, if
  96. possible.
  97.  
  98.  
  99.                             *perl-overview*
  100. Here is an overview of the functions that are available to Perl: >
  101.  
  102.   :perl VIM::Msg("Text")        # displays a message
  103.   :perl VIM::Msg("Error", "ErrorMsg")    # displays an error message
  104.   :perl VIM::Msg("remark", "Comment")    # displays a highlighted message
  105.   :perl VIM::SetOption("ai")        # sets a vim option
  106.   :perl $nbuf = VIM::Buffers()        # returns the number of buffers
  107.   :perl @buflist = VIM::Buffers()    # returns array of all buffers
  108.   :perl $mybuf = (VIM::Buffers('qq.c'))[0] # returns buffer object for 'qq.c'
  109.   :perl @winlist = VIM::Windows()    # returns array of all windows
  110.   :perl $nwin = VIM::Windows()        # returns the number of windows
  111.   :perl ($success, $v) = VIM::Eval('&path') # $v: option 'path', $success: 1
  112.   :perl ($success, $v) = VIM::Eval('&xyz')  # $v: '' and $success: 0
  113.   :perl $v = VIM::Eval('expand("<cfile>")') # expands <cfile>
  114.   :perl $curwin->SetHeight(10)        # sets the window height
  115.   :perl @pos = $curwin->Cursor()    # returns (row, col) array
  116.   :perl @pos = (10, 10)
  117.   :perl $curwin->Cursor(@pos)        # sets cursor to @pos
  118.   :perl $curwin->Cursor(10,10)        # sets cursor to row 10 col 10
  119.   :perl $mybuf = $curwin->Buffer()    # returns the buffer object for window
  120.   :perl $curbuf->Name()            # returns buffer name
  121.   :perl $curbuf->Number()        # returns buffer number
  122.   :perl $curbuf->Count()        # returns the number of lines
  123.   :perl $l = $curbuf->Get(10)        # returns line 10
  124.   :perl @l = $curbuf->Get(1 .. 5)    # returns lines 1 through 5
  125.   :perl $curbuf->Delete(10)        # deletes line 10
  126.   :perl $curbuf->Delete(10, 20)        # delete lines 10 through 20
  127.   :perl $curbuf->Append(10, "Line")    # appends a line
  128.   :perl $curbuf->Append(10, "Line1", "Line2", "Line3") # appends 3 lines
  129.   :perl @l = ("L1", "L2", "L3")
  130.   :perl $curbuf->Append(10, @l)        # appends L1, L2 and L3
  131.   :perl $curbuf->Set(10, "Line")    # replaces line 10
  132.   :perl $curbuf->Set(10, "Line1", "Line2")    # replaces lines 10 and 11
  133.   :perl $curbuf->Set(10, @l)        # replaces 3 lines
  134. <
  135.                             *perl-Msg*
  136. VIM::Msg({msg}, {group}?)
  137.             Displays the message {msg}.  The optional {group}
  138.             argument specifies a highlight group for Vim to use
  139.             for the message.
  140.  
  141.                             *perl-SetOption*
  142. VIM::SetOption({arg})    Sets a vim option.  {arg} can be any argument that the
  143.             ":set" command accepts.  Note that this means that no
  144.             spaces are allowed in the argument!  See |:set|.
  145.  
  146.                             *perl-Buffers*
  147. VIM::Buffers([{bn}...])    With no arguments, returns a list of all the buffers
  148.             in an array context or returns the number of buffers
  149.             in a scalar context.  For a list of buffer names or
  150.             numbers {bn}, returns a list of the buffers matching
  151.             {bn}, using the same rules as Vim's internal
  152.             |bufname()| function.
  153.  
  154.                             *perl-Windows*
  155. VIM::Windows([{wn}...])    With no arguments, returns a list of all the windows
  156.             in an array context or returns the number of windows
  157.             in a scalar context.  For a list of window numbers
  158.             {wn}, returns a list of the windows with those
  159.             numbers.
  160.  
  161.                             *perl-DoCommand*
  162. VIM::DoCommand({cmd})    Executes Ex command {cmd}.
  163.  
  164.                             *perl-Eval*
  165. VIM::Eval({expr})    Evaluates {expr} and returns (success, val).
  166.             success=1 indicates that val contains the value of
  167.             {expr}; success=0 indicates a failure to evaluate
  168.             the expression.  '@x' returns the contents of register
  169.             x, '&x' returns the value of option x, 'x' returns the
  170.             value of internal |variables| x, and '$x' is equivalent
  171.             to perl's $ENV{x}.  All |functions| accessible from
  172.             the command-line are valid for {expr}.
  173.  
  174.                             *perl-SetHeight*
  175. Window->SetHeight({height})
  176.             Sets the Window height to {height}, within screen
  177.             limits.
  178.  
  179.                             *perl-GetCursor*
  180. Window->Cursor({row}?, {col}?)
  181.             With no arguments, returns a (row, col) array for the
  182.             current cursor position in the Window.  With {row} and
  183.             {col} arguments, sets the Window's cursor position to
  184.             {row} and {col}.  Note that {col} is numbered from 0,
  185.             Perl-fashion, and thus is one less than the value in
  186.             Vim's ruler.
  187.  
  188. Window->Buffer()                    *perl-Buffer*
  189.             Returns the Buffer object corresponding to the given
  190.             Window.
  191.  
  192.                             *perl-Name*
  193. Buffer->Name()        Returns the filename for the Buffer.
  194.  
  195.                             *perl-Number*
  196. Buffer->Number()    Returns the number of the Buffer.
  197.  
  198.                             *perl-Count*
  199. Buffer->Count()        Returns the number of lines in the Buffer.
  200.  
  201.                             *perl-Get*
  202. Buffer->Get({lnum}, {lnum}?, ...)
  203.             Returns a text string of line {lnum} in the Buffer
  204.             for each {lnum} specified. An array can be passed
  205.             with a list of {lnum}'s specified.
  206.  
  207.                             *perl-Delete*
  208. Buffer->Delete({lnum}, {lnum}?)
  209.             Deletes line {lnum} in the Buffer.  With the second
  210.             {lnum}, deletes the range of lines from the first
  211.             {lnum} to the second {lnum}.
  212.  
  213.                             *perl-Append*
  214. Buffer->Append({lnum}, {line}, {line}?, ...)
  215.             Appends each {line} string after Buffer line {lnum}.
  216.             The list of {line}s can be an array.
  217.  
  218.                             *perl-Set*
  219. Buffer->Set({lnum}, {line}, {line}?, ...)
  220.             Replaces one or more Buffer lines with specified
  221.             {lines}s, starting at Buffer line {lnum}.  The list of
  222.             {line}s can be an array.  If the arguments are
  223.             invalid, replacement does not occur.
  224.  
  225. $main::curwin
  226.             The current window object.
  227.  
  228. $main::curbuf
  229.             The current buffer object.
  230.  
  231.  
  232.  vim:tw=78:ts=8:ft=help:norl:
  233.